function  [bdrawp,m1,CC1,rej]=drawnres(y,x,prm,prprec,sig);
% function [bdrawp,m1,CC1]=drawnres(y,x,prm,prprec,sig); 
% Draw Coefficients from a Normal Distribution 
% and check whether the stationarity conditions are satisfied or not
% Note: the draw here will be reported whether stationary or not 
%       and rej will indicate if the root conditions are satisfied 
% To constraint the draw to be stationary use drawnsta.m 
%
% Prior ~ Normal( prm, prprec^(-1) )  
%         prprec is the precision  
% y      (Txn) 
% x      (TxK)  
% Prm    (Kx1)  Prior Mean 
% prprec (KxK)  Prior Precision
% Sig    (1x1)
%
% bdrawp (Kx1)is the draw from the posterior normal as a row vector 
% m1     (Kx1) is the posterior mean 
% CC1     (KxK) is the Cholelsky of the posterior variance 
%         V1= CC1'*CC1
%rej(ect)     = 0 if draw is stationarity
%             = 1 if not stationary 
[ty,ny]=size(y); 
[tx,nx]=size(x); 
nk=length(prm);
if tx~=ty
    error('Not equal number of observations in drawcoef'); 
end; 
V1=( prprec+( (1/sig)*(x'*x) ) ) \ eye(nk) ; % Posterior Variance  
m1=V1*(prprec*prm + (1/sig)*(x'*y) );        % Posterior Mean  
CC1=chol(V1); 
bdraw=m1+CC1'*randn(nk,1);
bdrawp=bdraw'; 
if min( abs( rootpol([1 bdrawp]) ) ) >=1.0001; 
    rej=0; 
else;
    rej=1; 
end; 
